import java.util.*;
import java.io.* ;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class MainDP41 {
    static Read scan = new Read() ;
    static PrintWriter out = new PrintWriter(
        new BufferedWriter(
            new OutputStreamWriter(System.out)
        )
    );
    public static void main(String[] args) throws IOException {

        int n = scan.nextInt() ;
        int v = scan.nextInt() ;
        int[] arrS = new int[n + 1] ;
        int[] arrV = new int[n + 1] ;
        for (int i = 1 ; i <= n ; i ++) {
            arrV[i] = scan.nextInt() ;
            arrS[i] = scan.nextInt() ;
        }
        int[] dp = new int[v + 1] ;
        // 初始化dp表,这里本来第0行都是 0

        for (int i = 1 ; i <= n ; i ++) {
            for (int j = v ; j >= 1 ; j --) {
                if (j - arrV[i] >= 0 ) {
                    dp[j] = Math.max(dp[j], arrS[i] + dp[j - arrV[i]]) ;
                }
            }
        }
        out.println(dp[v]);

        // 2. 刚好体积 == j 时 ;
        dp = new int[v + 1] ;
        // 初始化dp表
        for (int i = 1 ; i <= v; i++) dp[i] = -1 ;

        for (int i = 1 ; i <= n ; i ++) {
            for (int j = v ; j >= 1 ; j --) {
                if (j - arrV[i] >= 0 && dp[j - arrV[i]] != -1) {
                    dp[j] = Math.max(dp[j], arrS[i] + dp[j - arrV[i]]) ;
                }
            }
        }
        out.println(dp[v] == -1 ? 0 : dp[v]);


        out.close() ;
    }


}
